Telegram Group & Telegram Channel
Самые интересные фичи Python 3.12, которые уже можно тестить и встраивать в проекты


1️⃣ Улучшенный match-case

Теперь можно использовать «захват» значений прямо в паттернах:


def http_status(code):
match code:
case 200 | 201 | 202 as ok:
return f"Success: {ok}"
case 400 as bad | 404 as bad:
return f"Client error: {bad}"
case _:
return "Other"


Большая гибкость и меньше «шаблонных» переменных!



2️⃣ Новый оператор f”{…=}" для отладки

Позволяет вывести и имя, и значение переменной в одной строке:


user = "Alice"
age = 29
print(f"{user=}, {age=}")
# Выведет: user='Alice', age=29


Больше никаких лишних print("user", user)!



3️⃣ Оптимизация работы с памятью и скорость

Команда CPython продолжает ускорение интерпретатора:

* Выделение объектов стало быстрее
* Сборщик мусора реже «паузит» приложение

Это особенно заметно в тяжёлых сервисах и бэкендах.



4️⃣ Новые API для типов

Добавили typing.Self и более гибкие Generic-типизации:


from typing import Self

class Builder:
def set_name(self, name: str) -> Self:
self.name = name
return self

b = Builder().set_name("Demo")


Удобнее писать цепочки вызовов без «# type: ignore»!



💡 Что попробовать прямо сейчас?

1. Установить Python 3.12 pre-release:


pyenv install 3.12.0b4

2. Переписать пару функций с match-case.
3. Пощупать f"{var=}" в дебаге.

👉@BookPython



tg-me.com/BookPython/3674
Create:
Last Update:

Самые интересные фичи Python 3.12, которые уже можно тестить и встраивать в проекты


1️⃣ Улучшенный match-case

Теперь можно использовать «захват» значений прямо в паттернах:


def http_status(code):
match code:
case 200 | 201 | 202 as ok:
return f"Success: {ok}"
case 400 as bad | 404 as bad:
return f"Client error: {bad}"
case _:
return "Other"


Большая гибкость и меньше «шаблонных» переменных!



2️⃣ Новый оператор f”{…=}" для отладки

Позволяет вывести и имя, и значение переменной в одной строке:


user = "Alice"
age = 29
print(f"{user=}, {age=}")
# Выведет: user='Alice', age=29


Больше никаких лишних print("user", user)!



3️⃣ Оптимизация работы с памятью и скорость

Команда CPython продолжает ускорение интерпретатора:

* Выделение объектов стало быстрее
* Сборщик мусора реже «паузит» приложение

Это особенно заметно в тяжёлых сервисах и бэкендах.



4️⃣ Новые API для типов

Добавили typing.Self и более гибкие Generic-типизации:


from typing import Self

class Builder:
def set_name(self, name: str) -> Self:
self.name = name
return self

b = Builder().set_name("Demo")


Удобнее писать цепочки вызовов без «# type: ignore»!



💡 Что попробовать прямо сейчас?

1. Установить Python 3.12 pre-release:


pyenv install 3.12.0b4

2. Переписать пару функций с match-case.
3. Пощупать f"{var=}" в дебаге.

👉@BookPython

BY Библиотека Python разработчика | Книги по питону


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/BookPython/3674

View MORE
Open in Telegram


Библиотека Python разработчика Telegram | DID YOU KNOW?

Date: |

NEWS: Telegram supports Facetime video calls NOW!

Secure video calling is in high demand. As an alternative to Zoom, many people are using end-to-end encrypted apps such as WhatsApp, FaceTime or Signal to speak to friends and family face-to-face since coronavirus lockdowns started to take place across the world. There’s another option—secure communications app Telegram just added video calling to its feature set, available on both iOS and Android. The new feature is also super secure—like Signal and WhatsApp and unlike Zoom (yet), video calls will be end-to-end encrypted.

How to Buy Bitcoin?

Most people buy Bitcoin via exchanges, such as Coinbase. Exchanges allow you to buy, sell and hold cryptocurrency, and setting up an account is similar to opening a brokerage account—you’ll need to verify your identity and provide some kind of funding source, such as a bank account or debit card. Major exchanges include Coinbase, Kraken, and Gemini. You can also buy Bitcoin at a broker like Robinhood. Regardless of where you buy your Bitcoin, you’ll need a digital wallet in which to store it. This might be what’s called a hot wallet or a cold wallet. A hot wallet (also called an online wallet) is stored by an exchange or a provider in the cloud. Providers of online wallets include Exodus, Electrum and Mycelium. A cold wallet (or mobile wallet) is an offline device used to store Bitcoin and is not connected to the Internet. Some mobile wallet options include Trezor and Ledger.

Библиотека Python разработчика from pl


Telegram Библиотека Python разработчика | Книги по питону
FROM USA